﻿using Product.Domain.Repository;
using Product.Domain.Entity;
using System.Linq;
using System;
using Microsoft.EntityFrameworkCore;

namespace Product.EntityFrameworkCore.Repository
{
    public class SkuReposiory : ISkuReposiory
    {
        private readonly ProductContext _productContext;
        public SkuReposiory(ProductContext productContext)
        {
            _productContext = productContext;
        }

        /// <summary>
        /// 获取今天最大的SkuNo
        /// </summary>
        public string GetTodayMaxSkuNo()
        {
            var startDate = DateTime.Now.Date;
            var endDate = DateTime.Now.AddDays(1);
            var skuNo = _productContext.Sku.AsNoTracking()
                .Where(e => e.CreateTime >= startDate && e.CreateTime < endDate)
                .Max(e => e.SkuNo);
            return skuNo;
        }


    }
}
